//
//  TurntableItem.swift
//  RotationViewDemo
//
//  Created by 冉彬 on 2023/7/17.
//

import UIKit

class TurntableItem: UIView {
    
    var identifier: String = "TurntableItem"
    
    /// 锚点（item上与圆心等距离的点,参考系为item自己）
    var anchorpoint: CGPoint = CGPoint.zero
    
    /// 更新位置
    /// - Parameter aPoint: 锚点位置（参考系为item的父控件）
    func refreshPoint(_ aPoint: CGPoint) {
        self.frame = CGRect(origin: CGPoint(x: aPoint.x - anchorpoint.x, y: aPoint.y - anchorpoint.y), size: self.bounds.size)
    }
    
    
    private override init(frame: CGRect) {
        super.init(frame: frame)
    }
    
    
    init(identifier: String, size: CGSize, anchorpoint: CGPoint? = nil) {
        super.init(frame: CGRect(origin: .zero, size: size))
        self.identifier = identifier
        self.anchorpoint = anchorpoint ?? CGPoint(x: size.width/2, y: size.height/2)
    }
    
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}


